<?php

namespace App\Http\Requests\Biz;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;

class ShopStore extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'branch_id' => 'required',
            'name' => 'required',
            'type' => 'required',
            'trade' => 'required',
            'category_id' => 'required',
            'member_id' => 'required',
            'staff_id' => 'required',
            'progress' => 'required',
            //'lon'=>'required_with:lat|numeric',
            //'lat'=>'required_with:lon|numeric',
        ];
    }


    public function failedValidation(Validator $validator)
    {
        if ($this->wantsJson() || $this->ajax()) {
            throw new HttpResponseException(
                new JsonResponse([
                    'message' => $validator->errors()->first(),
                    'data' => $validator->errors()
                ],422)
            );
        } else {
            parent::failedValidation($validator);
        }
    }

}
